<template>
  <div class="container">
    <div id="index-banner" v-show="bannarShow" v-if="bannerList.length>0">
      <mt-swipe :auto="4000">
        <mt-swipe-item v-for="(item,index) in bannerList" :key="index"><img :src="item.imgUrl" @click="toUrl(item,index)"></mt-swipe-item>
      </mt-swipe> 
    </div>
    <div id="nav-bar">
      <ul class="clearfix">
        <li v-for="(item,index) in wxMenuList" :key="index" @click="ToUrl(item,index)">
          <div class="item">
            <img :src="item.icon">
            <p>{{item.label}}</p>
          </div>
        </li>
      </ul>
    </div>
    <van-button size="large" @click="$store.dispatch('toSetGoodsList',!showGoodsList)">点击加载商品列表</van-button>
    <!--商品列表-->
    <GoodsList :list="goodsList"></GoodsList>
  </div>
</template>
<script>
import { Swipe, SwipeItem, Toast } from "mint-ui";
import { Button } from "vant";
import { getHome, getGoodsList } from "@/api";
import wx from "weixin-js-sdk";
//商品列表
import GoodsList from "@/components/goods/goodsList";
import { mapState } from "vuex";
export default {
  components: {
    GoodsList,
    [Button.name]: Button
  },
  data() {
    return {
      bannerList: [],
      wxMenuList: [],
      goodsList: [],
      bannarShow: true
    };
  },
  computed: {
    showGoodsList() {
      return this.$store.state.showGoodsList
    }
  },
  methods: {
    async getHome() {
      let homeData = await getHome({ officialName: "前海有车" });
      let goodsList = await getGoodsList();
      if (homeData.code == 2000) {
        this.bannerList = homeData.data.bannerList;
        this.wxMenuList = homeData.data.wxMenuList;
      }
      //模拟商品数据
      if (goodsList.status == 200) {
        goodsList.data.map((value, index) => {
          value.thumbnail = JSON.parse(value.thumbnail)[0];
        });
        this.goodsList = goodsList.data;
      }
    },
    ToUrl(item, index) {
      this.$router.push({
        path: item.router,
        query: { officialName: "前海有车" }
      });
    }
  },
  mounted() {
    this.getHome();
  }
};
</script>
<style lang="scss" scoped>
#index-banner {
  height: 295px;
  .mint-swipe img {
    width: 100%;
    height: 100%;
  }
  .mint-swipe .mint-swipe-indicator {
    opacity: 1;
    background: #fff;
  }
  .mint-swipe .mint-swipe-indicator.is-active {
    opacity: 1;
    background: #14a0ff;
  }
}
#nav-bar {
  padding-top: 35px;
  background-color: #fff;
  ul {
    width: 100%;
  }
  li {
    float: left;
    width: 25%;
    text-align: center;
    img {
      width: 98px;
    }
    p {
      margin: 12px 0 24px;
      font-family: MicrosoftYaHei;
      font-size: 24px;
      font-weight: normal;
      font-stretch: normal;
      letter-spacing: 0px;
      color: #333333;
    }
  }
}
</style>
